package cn.edu.ujn.lab3.service.impl;

import cn.edu.ujn.lab3.entity.Page;
import cn.edu.ujn.lab3.entity.user;
import cn.edu.ujn.lab3.entity.userDTO;
import cn.edu.ujn.lab3.mapper.userMapper;
import cn.edu.ujn.lab3.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;
@Service
public class userServiceImpl implements IUserService {
    @Autowired
    private userMapper userMapper;

    @Override
    public Boolean addUser(user user) {
        Boolean flag = userMapper.addUser(user);
        return flag;
    }

    @Override
    public Boolean updateUser(userDTO user) {
        Boolean flag = userMapper.updateUser(user);
        return flag;
    }

    @Override
    public Boolean deleteUser(Integer id) {
        Boolean flag = userMapper.deleteUser(id);
        return flag;
    }

    @Override
    public Boolean login(String code,String password, HttpSession session) {
        user user = userMapper.checkUser(code,password);
        if(user == null){
            session.setAttribute("msg","账号或密码错误");
            return false;
        }
        session.setAttribute("user",user);
        return true;
    }

    @Override
    public List<user> selectByName(String name) {
       return userMapper.selectByName(name);
    }

    @Override
    public List<user> selectAll() {
        return userMapper.selectAll();
    }

    @Override
    public user findUserBycode(String code) {
        user user = userMapper.findUserBycode(code);
        return user;
    }

    @Override
    public List<userDTO> selectUserByPage(Page page) {
        return userMapper.selectUserByPage(page);
    }

    @Override
    public user checkUser(String code, String password) {
        return userMapper.checkUser(code,password);
    }

}
